<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

class Smslog_m extends FOX_Model
{

	function __construct ()
	{
		parent::__construct();
	}

    /**
     * @param $id
     * @return mixed
     * 查询单条
     */
    public function get_sms_log_by_id($id){
        $query = $this->db
            ->select('*')
            ->get_where('sms_log', array('id'=>$id));
        return $query->row_array();
    }

    /**
     * @param $id
     * @param $data
     * @return bool
     * 修改商品信息
     */
    public function sava_sms_log($id,$data){

        $this->db->where('id',$id);
        $this->db->update('sms_log', $data);
        return ($this->db->affected_rows() > 0) ? TRUE : FALSE;
    }

    /**
     * @param $data
     * @return bool
     * 新增商品
     */
    public function add_sms_log($data){

        $this->db->insert('sms_log',$data);
        if($this->db->affected_rows() > 0){
            return $this->db->insert_id();
        }else{
            return false;
        }
    }

    /**
     * @return mixed
     * 查询所有商品
     */
    public function get_all_sms_log(){
        $this->db->select('*');
        $this->db->from('sms_log');
        $query = $this->db->get();
        if($query->num_rows() > 0){
            return $query->result_array();
        }
    }


    /**
     * 根据条件查询记录
     */
    public function get_sms_log_by($mobile, $yzm, $checked){
        $map = "mobile = '".$mobile."' AND yzm = '".$yzm."' AND is_checked = $checked";
        $sql = "SELECT * FROM {$this->db->dbprefix}sms_log  where $map";
        $query=$this->db->query($sql);
        return $query->row_array();
    }

    /**
     * 根据条件查询记录
     */
    public function get_sms_log_by_type($mobile ,$type){
        $map = "mobile = '".$mobile."' AND type = '".$type."'";
        $sql = "SELECT * FROM {$this->db->dbprefix}sms_log  where $map";
        $query=$this->db->query($sql);
        return $query->row_array();
    }

    /**
     * @param $where
     * @return bool
     * 删除商品
     */
    public function delete_sms_log_by($where){
        $this->db->where($where)->delete('sms_log');
        return ($this->db->affected_rows() > 0) ? TRUE : FALSE;
    }
}
